package com.maruping.disk.login.control;

import com.maruping.disk.user.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/register")

public class RegisterControl {

    @Resource
    private HttpSession httpSession;

    @Resource
    private UserService userService;

    @GetMapping("/page")
    public String loginPage()
    {
        return "login/loginPage";
    }





 /*   // 发送验证码
    @RequestMapping("/sendCode")
    @ResponseBody
    public Map<String, Object> sendCode(@RequestParam String mobile) {
        Map<String, Object> res = new HashMap<>();
        try {
            smsService.sendCode(mobile); // 调用短信服务发送验证码
            res.put("success", true);
        } catch (Exception e) {
            res.put("success", false);
            res.put("msg", e.getMessage());
        }
        return res;
    }

    // 处理注册
    @RequestMapping("/register")
    @ResponseBody
    public Map<String, Object> register(
            @RequestParam String mobile,
            @RequestParam String code,
            @RequestParam String nickname,
            @RequestParam String password
    ) {
        Map<String, Object> res = new HashMap<>();
        try {
            // 1. 验证验证码
            boolean isCodeValid = smsService.verifyCode(mobile, code);
            if (!isCodeValid) {
                res.put("success", false);
                res.put("msg", "验证码错误或已过期");
                return res;
            }

            // 2. 构建用户实体
            PtUserEntity user = new PtUserEntity();
            user.setMobile(mobile);
            user.setNiceName(nickname);
            user.setUserName(mobile); // 用手机号作为登录名
            user.setPassword(password); // 密码会在服务层加密

            // 3. 注册用户
            userService.register(user);
            res.put("success", true);
        } catch (Exception e) {
            res.put("success", false);
            res.put("msg", e.getMessage());
        }
        return res;
    }*/


}
